﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Clipboard.Tools
{
    public class TimeAgoConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is DateTime createdTime)
            {
                var timeDifference = DateTime.Now - createdTime;

                // 计算差异并格式化为字符串
                if (timeDifference.TotalDays >= 1)
                {
                    int days = (int)timeDifference.TotalDays;
                    return $"{days} 天前";
                }
                else if (timeDifference.TotalHours >= 1)
                {
                    int hours = (int)timeDifference.TotalHours;
                    return $"{hours} 小时前";
                }
                else if (timeDifference.TotalMinutes >= 1)
                {
                    int minutes = (int)timeDifference.TotalMinutes;
                    return $"{minutes} 分钟前";
                }
                else
                {
                    return "刚刚";  // 小于 1 分钟
                }
            }
            return string.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 不需要反向转换
            throw new NotImplementedException();
        }
    }
}
